<template>
  <div class="login">
    <div class="mask"></div>
    <div class="login-box">
      <div class="close">
        <img
          @click="$store.commit('upisShow', false)"
          src="../../assets/images/login/userArrow.png"
          alt=""
        />
      </div>
      <ul class="login-type flex">
        <li :class="{ active: num === 1 }" @click="num = 1">手机号码登录</li>
        <li :class="{ active: num === 2 }" @click="num = 2">微信扫码登录</li>
      </ul>
      <!-- 手机登录 -->
      <div class="phone-login" v-show="num === 1">
        <div class="form-item">
          <input type="text" placeholder="请输入手机号" />
        </div>
        <!-- 滑动验证 -->
        <div class="form-item">
          <slide-verify
            :l="42"
            :r="20"
            :w="400"
            :h="140"
            :accuracy="100"
            @success="onSuccess"
            @fail="onFail"
            @refresh="onRefresh"
            :style="{ width: '100%' }"
            class="slide-box"
            ref="slideBlock"
            :slider-text="msg"
          ></slide-verify>
        </div>
        <div class="form-item">
          <input type="text" placeholder="请输入短信验证码" />
          <span class="btn">获取验证码</span>
        </div>
        <div class="form-item">
          <div class="btn big">登录</div>
        </div>
      </div>
      <!-- 微信登录 -->
      <div class="wx-login" v-show="num === 2"></div>
    </div>
  </div>
</template>
 
<script>
//号码验证
// import { validateTelephone } from "../../utils/zhengze";
export default {
  data() {
    return {
      //手机或者微信登录
      num: 1,
      msg: "向右滑动",
    };
  },
  methods: {
    // 拼图成功
    onSuccess(times) {
      let ms = (times / 1000).toFixed(1);
      this.msg = "login success, 耗时 " + ms + "s";
    },
    // 拼图失败
    onFail() {
      this.onRefresh(); // 重新刷新拼图
    },
    // 拼图刷新
    onRefresh() {
      this.msg = "再试一次";
    },
    // 点击登录按钮
    submitFn(formName) {
      if (this.msg == "再试一次" || this.msg == "向右滑动") {
        console.log("请滑动拼图");
      } else {
        console.log("开始登录");
      }
    },
  },
};
</script>
 
<style lang = "less" scoped>
.login {
  background-color: rgba(0, 0, 0, 0.5);
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  .mask {
    position: absolute;
    width: 100%;
    height: 100%;
  }
  .login-box {
    width: 555px;
    height: 423px;
    box-sizing: border-box;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-image: url("../../assets/images/login/loginBg.png");
    padding: 40px 80px;
    .close {
      position: absolute;
      top: 20px;
      right: 60px;
      img {
        cursor: pointer;
      }
    }
    .login-type {
      justify-content: center;
      li {
        padding: 0 10px;
        cursor: pointer;
        color: #ccc;
        &.active {
          color: #333;
        }
        &:nth-child(2) {
          border-left: 1px solid #333;
        }
      }
    }
    .phone-login {
      padding-top: 20px;
      .form-item {
        margin-bottom: 20px;
        display: flex;
        input {
          box-sizing: border-box;
          padding: 0 10px;
          height: 50px;
          border: 1px solid #ccc;
          flex: 1;
          outline: none;
        }
        .btn {
          color: #fff;
          width: 120px;
          height: 50px;
          text-align: center;
          line-height: 50px;
          background-color: #0a328e;
          margin-left: 10px;
          cursor: pointer;
          &.big {
            width: 100%;
            margin: 0;
          }
        }
      }
    }
    .wx-login {
      #weixin {
        margin-left: 50px;
      }
    }
  }
}

/deep/.slide-box {
  width: 100%;
  position: relative;
  box-sizing: border-box;
  canvas {
    position: absolute;
    left: 0;
    top: -140px;
    display: none;
    width: 100%;
    box-sizing: border-box;
  }
  .slide-verify-block {
    width: 85px;
    height: 136px;
  }
  .slide-verify-refresh-icon {
    top: -140px;
    display: none;
  }
  &:hover {
    canvas {
      display: block;
    }
    .slide-verify-refresh-icon {
      display: block;
    }
  }
}
</style>